using System;
using System.Runtime.CompilerServices;
using Awaiter;
using Nsb.Classes;
using jQueryApi;

namespace Yoshi.Clusters
{
    [IgnoreNamespace]
    public class SearchCluster : Truple
    {
        private Truple _searchBtn;

        private SearchCluster(Await awp, jQueryObject insertAfter)
        {
            Element = jQuery.FromHtml("<div class='SearchCluster TrupleCluster'/>")
                ;

            Truple female = Checkbox("Female").SubHtml("span", "Female?").SubAttr("input", "checked", "checked");

            _searchBtn = Button("Search").SubValue("button", "Search");

            if (Script.IsValue(insertAfter))
            {
                Element.InsertAfter(insertAfter);
            }

            new Await()
                //.AddAw(FillDataFromAw, Data.My)
                //.AddFn(AttachEvents)
                .AddAw(SlideEmInAw)
                .Commit(awp);

        }

        public void Refresh()
        {
            new Await()
                .AddAw(Aw, Element)
                .AddDx(delegate { Element.Remove(); })
                .Commit();
        }

        private void SlideEmInAw(Await awp)
        {
            Await ani = new Await();
            ani.Sleep(500);
            AddSlideTruples(ani);
            ani.Sleep(100);
            ani.AddDx(delegate { jQuery.Select("button", _searchBtn.Element).Focus(); });
            ani.Commit(awp);
        }

        public static void Aw(Await awp, jQueryObject insertAfter)
        {
            //new SearchCluster(awp, insertAfter);
            awp.Done();
        }

    }
}
